{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bdbfe1e5-5e38-47c0-8373-0af17b3dc146",
   "metadata": {},
   "outputs": [],
   "source": [
    "# setting the environment variables\n",
    "import sys\n",
    "import os\n",
    "\n",
    "sys.path.insert(0, os.path.abspath('..'))\n",
    "\n",
    "from config import set_environment\n",
    "set_environment()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ed9d81de-3494-4f32-bbf1-5f9a131c707a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "Why did the light bulb go to therapy?\n",
      "\n",
      "Because it was having a dim bulb moment!\n",
      "Total Tokens: 27\n",
      "Prompt Tokens: 8\n",
      "Completion Tokens: 19\n",
      "Total Cost (USD): $5e-05\n"
     ]
    }
   ],
   "source": [
    "from langchain import OpenAI, PromptTemplate\n",
    "from langchain.callbacks import get_openai_callback\n",
    "\n",
    "llm_chain = PromptTemplate.from_template(\"Tell me a joke about {topic}!\") | OpenAI()\n",
    "with get_openai_callback() as cb:\n",
    "    response = llm_chain.invoke(dict(topic=\"light bulbs\"))\n",
    "    print(response)\n",
    "    print(f\"Total Tokens: {cb.total_tokens}\")\n",
    "    print(f\"Prompt Tokens: {cb.prompt_tokens}\")\n",
    "    print(f\"Completion Tokens: {cb.completion_tokens}\")\n",
    "    print(f\"Total Cost (USD): ${cb.total_cost}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44d08b80-2041-4216-9942-7d949f30ad6f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
